<?php
/**
 * Created by PhpStorm.
 * User: apple
 * Date: 2020/10/13
 * Time: 6:26 PM
 */
namespace app\model;


use think\facade\Db;
use think\Model;

class IntegralLog extends Model
{
    protected $table = 'integral_log';
    protected $pk = 'integral_id';

    const PLAY_VIDEO = 1;
    const GOODS_EXCHANGE = 2;
    const SIGN_IN = 3;
    const TYPE_TEXT = [
        self::PLAY_VIDEO => '观看视频',
        self::GOODS_EXCHANGE => '兑换商品',
        self::SIGN_IN => '打卡',
    ];
    protected static function init(){
        //TODO:初始化内容
    }


    private static function _getListField(){
        return [
            'integral_id' => 'integralId',
            'integral_num' => 'integralNum',
            'integral_remark' => 'remark',
            'integral_create_time' => 'createTime'
        ];
    }
    public function addLog($data){
        $data['integral_create_time'] = $data['integral_update_time'] = time();
        return Db::table('integral_log')->insertGetId($data);
    }

    public function getIntegralLogListByCondition($where = [],$order = 'integral_id desc',$field = '')
    {
        $field = $field ?: self::_getListField();
        $list = Db::table('integral_log')
            ->where($where)
            ->field($field)
            ->order($order)
            ->paginate(input('param.pageSize'))
            ->render();
        return $list;
    }

}